package com.baizhi.springboot.controller;

import com.baizhi.springboot.entity.Inform;
import com.baizhi.springboot.entity.Meeting;
import com.baizhi.springboot.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class MeetingController {
    @Autowired
    private MeetingService meetingService;

    @RequestMapping("/selectMeetingByPage")
    public Map selectMeetingByPage(Integer page,Integer limit) {
        return meetingService.selectMeetingByPage(page,limit);
    }
    @RequestMapping("/insertMeeting")
    public Map insertMeeting(Meeting meeting) {

        HashMap<Object, Object> map = new HashMap<>();

        try {
            meetingService.insertMeeting(meeting);
            map.put("isAdd", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isAdd", false);
        }
        return map;
    }
    @RequestMapping("/deleteMeeting")
    public Map  deleteMeeting(Integer id){
        HashMap<Object, Object> map = new HashMap<>();

        try {
            meetingService.deleteMeeting(id);
            map.put("isDelete", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isDelete", false);
        }
        return map;
    }

    @RequestMapping("/selectOneMeeting")
    public Map selectOneMeeting(Integer id, HttpSession session) {
        Meeting meeting= meetingService.selectOneMeeting(id);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("meeting", meeting);
        return map;
    }

    @RequestMapping("/updateMeeting")
    public Map updateMeeting(Meeting meeting) {
        HashMap<Object, Object> map = new HashMap<>();
        try {
            //System.out.println(label);
            meetingService.updateMeeting(meeting);
            map.put("isUpdate", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("isUpdate", false);
        }
        return map;
    }


}
